var pageNo = 0;
var totalPage = 0;
$(function(){
	/* 初始化数据  */
	getFriends();
	
	/* 页码加载 */
	if(totalPage == 0){
		$("#page").html("<tr><td  colspan='4'>暂无数据</td></tr>");
	}else{
		$("#page").Page({
			totalPages : totalPage,//分页总数
			liNums : 7,//分页的数字按钮数(建议取奇数)
			activeClass : 'activP', //active 类样式定义
		    hasFirstPage: true,//whether has first button
		    hasLastPage: true,//whether has last button
		    hasPrv: true,//whether has prev button
		    hasNext: true,//whether has next button
			callBack : function(page){
				pageNo = page;
				getFriends();
			}
		});
	}
	
});

function getFriends(){
	$.ajax({
		url:g_requestContextPath + "/user/myFriends",
		type:"post",
		dataType:"json",
		async: false,
		data:{
			"pageNo":pageNo
		},
		success:function(data){
			totalPage = Math.ceil(parseInt(data.count) / 5);
			var friends = data.friends;
			var friendsHtml = "";
			for (var i = 0; i < friends.length; i++) {
				friendsHtml += "<tr>";
				friendsHtml += "<td>"+friends[i].mobile+"</td>";
				friendsHtml += "<td>"+friends[i].createTime+"</td>";
				if(friends[i].verified){
					friendsHtml += "<td>已认证</td>";
				}else{
					friendsHtml += "<td>未认证</td>";
				}
				friendsHtml += "<td>"+friends[i].investCount+"笔</td>";
				friendsHtml += "</tr>";
			}
			$("#friendList").html(friendsHtml);
		}
	});
}